package ru.eas.tetris.tetromino;

/**
 * @author aesipov
 */
public class TTetromino implements RotatableTetromino
{
    private static final boolean[][] NORTH = { { true, false }, { true, true }, { true, false } };
    private static final boolean[][] EAST  = { { false, true, false }, { true, true, true } };
    private static final boolean[][] SOUTH = { { false, true }, { true, true }, { false, true } };
    private static final boolean[][] WEST  = { { true, true, true }, { false, true, false } };

    private boolean[][][] states = {NORTH, EAST, SOUTH, WEST};

    private int stateNumber = 0;

    @Override
    public void rotateRight()
    {
        stateNumber++;
        stateNumber %= states.length;
    }

    @Override
    public void rotateLeft()
    {
        stateNumber--;
        if (stateNumber < 0) {
            stateNumber = states.length - 1;
        }
    }

    @Override
    public int getWidth()
    {
        boolean[][] state = states[stateNumber];
        return state.length;
    }

    @Override
    public int getHeight()
    {
        boolean[][] state = states[stateNumber];
        return state[0].length;
    }

    @Override
    public boolean isSquare(int x,
                            int y)
    {
        boolean[][] state = states[stateNumber];
        return state[x][y];
    }
}
